{extend name="base/frame" /}
{block name="title"}新增{/block}
{block name="main"}
<form action="" method="post" class="layui-form">
    <input type="hidden" id="pic" name="pic" value="{$info['pic']|default=''}">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="name" value="{$info['name']|default=''}"  class="layui-input" required>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="number" name="sort" value="{$info['sort']|default='0'}"  class="layui-input" required>
        </div>
        <div class="layui-form-mid layui-word-aux">正序</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="upload_btn">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <div id="pic_pic" class="upload_pic">
                {notempty name="info.pic"}
                <img src='{$resurl}{$info.pic}?x-oss-process=image/resize,m_fill,h_40,w_40'/>
                {/notempty}
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级分类</label>
        <div class="layui-input-inline">
            <select id="up_id" name="up_id">
                <option value="0"  {eq name="info['up_id']|default='0'" value="0"}selected{/eq}>顶级分类</option>
                {volist name='top_cate_lists' id='item'}
                <option value="{$item['id']}"  {eq name="info['up_id']|default='0'" value="$item.id"}selected{/eq}>{$item['name']}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否展示</label>
        <div class="layui-input-inline">
            <input type="radio" name="isshow" value="0" title="否" {eq name="info['isshow']|default='1'" value="0"
                   }checked{/eq}>
            <input type="radio" name="isshow" value="1" title="是" {eq name="info['isshow']|default='1'" value="1"
                   }checked{/eq}>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否首页展示</label>
        <div class="layui-input-inline">
            <input type="radio" name="isshow_sy" value="0" title="否" {eq name="info['isshow_sy']|default='1'" value="0"
                   }checked{/eq}>
            <input type="radio" name="isshow_sy" value="1" title="是" {eq name="info['isshow_sy']|default='1'" value="1"
                   }checked{/eq}>
        </div>
    </div>


    <button id="submit" class="layui-btn" style="margin-left: 110px;">确定</button>
</form>

{/block}
{block name="script"}
<script>
    var resurl="{$resurl}";
    var uploadInst = layui.upload.render({
        elem: '#upload_btn'
        , url: '/admin/index/upload?dir=article'
        , done: function (res) {
            var pic=res.result
            //上传成功
            if (res.error_code == 0) {
                $('#pic').val(pic);
                $("#pic_pic").html("<img src='" + resurl + pic + "?x-oss-process=image/resize,m_fill,h_40,w_40'/>")
            }
            if (res.error_code > 0) {
                return layer.msg('上传失败');
            }
        }
        , error: function () {

        }
    });
</script>
{/block}